import {
  Controller,
  Post,
  Get,
  Body,
  Request,
  HttpCode,
  HttpStatus,
  UseGuards,
} from '@nestjs/common';
import { ApiBearerAuth, ApiTags, ApiOperation } from '@nestjs/swagger';
import { AuthService } from './auth.service';
import { AuthGuard } from '@nestjs/passport';
import { Public } from 'src/common/public.decorator';
import { SignInDto } from './dto/auth.dto';

@ApiTags('auth')
@Controller('auth')
export class AuthController {
  constructor(private readonly authService: AuthService) {}

  @Public()
  @Post('login')
  @ApiOperation({ summary: '登陆' })
  @HttpCode(HttpStatus.OK)
  login(@Body() signInDto: SignInDto) {
    return this.authService.login(signInDto);
  }

  @Public()
  @Post('register')
  @ApiOperation({ summary: '注册' })
  @HttpCode(HttpStatus.OK)
  register(@Body() userInfo: SignInDto) {
    console.log(userInfo);
    return this.authService.register(userInfo);
  }

  @Get('profile')
  @ApiOperation({ summary: '获取个人信息' })
  @ApiBearerAuth()
  @UseGuards(AuthGuard())
  getProfile(@Request() req) {
    return req.user;
  }
}
